package com.atguigu.lease.web.admin.controller.apartment;


import com.atguigu.lease.common.result.Result;
import com.atguigu.lease.web.admin.service.FileService;
import io.minio.errors.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;


//当前端页面点击上传图片按钮 选择图片后,会请求这个接口,将图片的url响应给前端
@Tag(name = "文件管理")
@RequestMapping("/admin/file")
@RestController
public class FileUploadController {

    @Autowired
    private FileService fileService;

    @Operation(summary = "上传文件")
    @PostMapping("upload")
    //RequestBody也能接收,但不建议用,它是专门接JSON的,似乎用RequestBody后,MultipartHttpMessageConverter 会进行转换
    //RequestParam能接受大多数传参,不只是两个位置的key-value,也能接收文件(似乎是form-data类型的)
    public Result<String> upload(@RequestParam MultipartFile file) throws Exception {
        String url = fileService.upload(file);
        return Result.ok(url);
    }

}